#pragma once
#include "mytypes.h"
#include "Polygon.h"

/*
Class: Visibility
Provides Visibility behaviors.
Next version will include:
2. Visibility test for the obstacles on the way

Client procedure:
1. Initialize the class for the object that the visibility will belong to (Player in this case).
2. Update the class with the current position (and soon, the direction) of the object
3. Get the visibility triangle and draw it.
*/

namespace poly
{
//States
#define VIS_FUNCTION_STEP	10
#define VIS_POLYGON			11

//Properties
#define VIS_DISTANCE		20
#define VIS_ANGLE			21
#define VIS_SPEED			22
#define VIS_VISPERC			23		//Cannot be changed by client
#define VIS_TRI_CENTER		24		//Cannot be changed by client
#define VIS_TRI_VERTEX1		25		//Cannot be changed by client
#define VIS_TRI_VERTEX2		26		//Cannot be changed by client

//Settings
#define VIS_ON				true
#define VIS_OFF				false
#define	VIS_GRAD			30		//Gradual increase
#define VIS_BOOL			31		//Step increase

	struct Vis_State{
		//Step type of the function (VIS_GRAD, VIS_BOOL)
		int		stateFunctionStep;
		//State of the polygon (VIS_ON, VIS_OFF)
		bool	statePolygon;
		//State of visibility. Client can't modify.
		bool	see;
	};
	struct Vis_Prop{
		//Distance object can see.
		float	distance;
		//Angle the object can see
		float	angle;
		//Speed of gradual increase
		float	speed;
		//Current percentage of vision quality
		float	visionPerc;
	};

	struct Vis_Triangle{
		float3	center;		//Center of the object
		float3  vertex1;	//Vertex1 of the visibility triangle
		float3	vertex2;	//Vertex2 of the visibility triangle
	};

	class Visibility{
	public:
		//Constructors
		Visibility();
		Visibility(float3 center, float angle, float distance);

		//Set
		bool	setState(int prop, int value);//Sets the property to the value
		bool	setState(int prop, bool value);
		bool	setProp(int prop, float value);

		//Get
		float3	getVisTri(int prop);//Gets the specified property of Vis_Triangle
		int		getState(int state);//Returns the value of states
		float	getProp(int prop);//Returns the value of properties
		Polygon	getPoly();//Returns m_VisPoly for the client to draw.

		//Verifies that the property is equal to the value
		bool	verify(int prop, float value);
		bool	verify(int prop, int value);
		bool	verify(int prop, bool value);

		//Procedure
		void	updateTri(float3 center, float rotationalSpeed);//Updates m_VisTri
		bool	canSee(float radius, float3 center);			//Can the object see another object with a bounding sphere raidus and center vector

		//Resets the class
		void	reset(float3 center, float angle, float distance);

		//Future functions
		void obstacleCheck(){}
	private:
		Vis_Triangle	m_VisTri;
		Vis_State		m_VisState;
		Vis_Prop		m_VisProp;
		Polygon			m_VisPoly;

		void	setPoly(float3 center);//sets Polygon;
	};
}
